﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ICSharpCode.SharpZipLib;
using XEAS.Framework.Data;

namespace XEAS.Engine.Business
{
    public class PluginManager
    {
        private string _pluginFolder;
        private string _cacheFolder;
        private string _temporaryFolder;

        public PluginManager()
        {
            
        }

        private sealed class PluginAccessLayer
        {
            private SQLiteAccessLayer _dataAccessLayer;

            public PluginAccessLayer(SQLiteAccessLayer dataAccessLayer)
            {
                _dataAccessLayer = dataAccessLayer;
            }

            public Guid Add(Guid pluginID, string name, string description, string author, string version, string website, string publishDate, string logoFileUrl)
            {
                Guid __newID = Guid.NewGuid();
                string[] __params = new string[]
                                       {
                                           "@ID", "@PluginID", "@Name", "@Description", "@Author", "@Version", "@Website",
                                           "@PublishDate", "@LogoFileUrl"
                                       };
                object[] __values = new object[]
                                        {
                                            __newID, pluginID, name, description, author, version, website, publishDate,
                                            logoFileUrl
                                        };

                _dataAccessLayer.ExecuteNonQuery(Sql.SYS_Plugin.Add, __params, __values, eExecutionType.TextCommand);

                return __newID;
            }

            public bool Edit(Guid id, Guid pluginID, string name, string description, string author, string version, string website, string publishDate, string logoFileUrl)
            {
                string[] __params = new string[]
                                       {
                                           "@ID", "@PluginID", "@Name", "@Description", "@Author", "@Version", "@Website",
                                           "@PublishDate", "@LogoFileUrl"
                                       };
                object[] __values = new object[]
                                        {
                                            id, pluginID, name, description, author, version, website, publishDate,
                                            logoFileUrl
                                        };

                _dataAccessLayer.ExecuteNonQuery(Sql.SYS_Plugin.Edit, __params, __values, eExecutionType.TextCommand);

                return true;
            }

            public bool Delete(Guid id)
            {
                string[] __params = new string[]
                                       {
                                           "@ID"
                                       };
                object[] __values = new object[]
                                        {
                                            id
                                        };

                _dataAccessLayer.ExecuteNonQuery(Sql.SYS_Plugin.Delete, __params, __values, eExecutionType.TextCommand);

                return true;
            }

            public DataSet ListAll()
            {
                return _dataAccessLayer.Execute(Sql.SYS_Plugin.ListAll, eExecutionType.TextCommand);
            }
        }
    }
}
